{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bce2c2cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['1', '3', '5', '7']\n",
      "['2', '4', '6', '8']\n",
      "['3', '5', '7', '9']\n",
      "['4', '6', '8', '10']\n",
      "['5', '7', '9', '11']\n",
      "['6', '8', '10', '12']\n",
      "['7', '9', '11', '13']\n",
      "['8', '10', '12', '14']\n",
      "['9', '11', '13', '15']\n",
      "['10', '12', '14', '16']\n",
      "['11', '13', '15', '17']\n",
      "['12', '14', '16', '18']\n",
      "['13', '15', '17', '19']\n",
      "['14', '16', '18', '20']\n"
     ]
    }
   ],
   "source": [
    "import csv\n",
    "with open('./data/demo.csv', newline='') as f:\n",
    "    reader = csv.reader(f)\n",
    "    # 安装行打印\n",
    "    for row in reader:\n",
    "        print(row)\n",
    "\n",
    "# 读取cvs数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1690bfab",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   a  3  5   7\n",
      "0  2  4  6   8\n",
      "1  3  5  7   9\n",
      "2  4  6  8  10\n",
      "-----------\n",
      "     a   3   5   7\n",
      "12  14  16  18  20\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "df=pd.read_csv('./data/demo.csv',encoding=\"utf-8\")\n",
    "# print(df)\n",
    "print(df.head(3))\n",
    "print('-----------')\n",
    "print(df.tail(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1aae7bf9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0  1  2  3]\n",
      " [ 4  5  6  7]\n",
      " [ 8  9 10 11]]\n",
      "[5 6]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "#产生3行4列的矩阵\n",
    "x=np.arange(0,12)\n",
    "x=x.reshape((3,4))\n",
    "print(x)\n",
    "\n",
    "#[a:b,c:d] 表示取a-b行，c-d列。a、c可以省略，表示从0开始\n",
    "#取x的第2行第2-3列\n",
    "y=x[1,1:3]\n",
    "print(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "dc3faaf4",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "positional argument follows keyword argument (1912369439.py, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn[24], line 2\u001b[0;36m\u001b[0m\n\u001b[0;31m    f = open('./data/demo.dat',encoding='utf-8','r')\u001b[0m\n\u001b[0m                                                   ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m positional argument follows keyword argument\n"
     ]
    }
   ],
   "source": [
    "# 读取dat数据\n",
    "f = open('./data/demo.dat',encoding='utf-8','r')\n",
    "line = f.readlines()\n",
    "f.close()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
